<?php
//require section
require_once dirname(__FILE__) . '/shared/config/config.php';
require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_multi_level.php';
require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_news.php';
require_once DOCUMENT_ROOT . DIR_INCLUDE . 'usable_functions.php';
$title = 'Tin Tức';

?>

<!DOCTYPE html>
<html>
    <head>
        <?php
        require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php';
        ?>
    </head>
    <body>
        <div class="uk-container uk-container-center uk-margin-top">
            <?php
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'menu.php';
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'slider.php';
            ?>

            <section id="main-content" class="ts-body-container">
                <div class="ts-left-wrapper">
                    <?php
                    if (!empty($_GET['cat_id'])) {
                        $cat_id = $_GET['cat_id'];
                        $category = api_news::get_news_category_by_id($cat_id);
                        show_news_category_group($category);
                    } else {
                        $category_groups = api_news::get_all_news_categories();
                        foreach ($category_groups as $group) {
                            show_news_category_group($group);
                        }
                    }
                    ?>
                </div>
                <script type="text/javascript">
                    function filldata(value) {
                        $.ajax({
                            type: "GET",
                            url: "<?php echo LINK_ROOT . DIR_AJAX; ?>news_folder_category.php",
                            data: "category_choosen_id=" + value,
                            success: function(result) {
                                $("#category-list").html(result);
                            }
                        });
                    }
                    $( document ).ready(function() {
                        filldata('<?php echo $cat_id; ?>');
                    });
                </script>
                <div class="ts-right-wrapper">
                    <div class="uk-panel uk-margin-bottom">
                        <div class="ts-category-title"><i class="uk-icon-list-ul"></i> Danh mục tin tức</div>
                        <ul id="category-list" class="ts-category-list">
                            <?php
                            show_news_root_list();
                            ?>
                        </ul>
                    </div>

                    <div class="uk-panel uk-margin-bottom">
                        <div class="ts-category-title"><i class="uk-icon-bolt"></i> Tin tức mới nhất</div>
                        <div class="ts-category-content">
                            <?php
                            latest_news(5);
                            ?>
                        </div>
                    </div>
                </div>
            </section>

            <?php
            require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php';
            ?>
        </div>
    </body>
</html>